import registnet.dao.*;

private class FieldItemRenderer implements ListitemRenderer {
	public void render(Listitem item, java.lang.Object data) {
		new Listcell(data).setParent(item);
	}
}
			
private class DataItemRenderer implements ListitemRenderer {
	public void render(Listitem item, java.lang.Object data) {
		for(int i=0; i<data.length; i++)
			new Listcell(data[i]).setParent(item);
	}
}
	
void retrieveFieldNames(String object){
	List data = new Vector();
	if (object.equals("College"))
		data = new College().getFields();
	
	else if (object.equals("Unit"))
		data = new Unit().getFields();

	else if (object.equals("Course"))
		data = new Course().getFields();
		
	else if (object.equals("Degree Course"))
		data = new DegreeCourse().getFields();
	
	else if (object.equals("Curriculum"))
		data = new Curriculum().getFields();
		
	String[] listModel = new String[data.size()];
	for (int i=0; i<data.size(); i++){
		listModel[i] = data.get(i);
		ListModel strset = new ListModelList(listModel);
		field_list.setModel(strset);
		field_list.setItemRenderer(new FieldItemRenderer());
	}
}


private class FieldEventListener implements EventListener {
	private String object;
	private List resultSet;
	public FieldEventListener (String object, List resultSet){
		this.object = object;
		this.resultSet = resultSet;
	}

	public void onEvent(Event event) throws UiException {
		result_list.removeChild(result_list.getListhead());
		Listhead listhead = new Listhead();
		listhead.setParent(result_list);
		Object[] selected = field_list.getSelectedItems().toArray();
		for (int i=0; i<selected.length; i++){
			Listheader lh = new Listheader(field_list.getModel().get(selected[i].getIndex()));
			lh.setParent(listhead);
		}
		
		String[] temp = new String[this.resultSet.size()];
		int numRows = temp.length;
		String[][] listModel = new String[numRows][selected.length];
		
		if (this.object.equals("College")){
			for (int i=0; i<temp.length; i++){
				for (int j=0; j<selected.length; j++){
					if (field_list.getModel().get(selected[j].getIndex()).equals("Code"))
						listModel[i][j] = this.resultSet.get(i).getCollegeCode();
					else if (field_list.getModel().get(selected[j].getIndex()).equals("Name"))
						listModel[i][j] = this.resultSet.get(i).getCollegeName();
				}
			}
		}
		
		else if (this.object.equals("Unit")){
			for (int i=0; i<temp.length; i++){
				for (int j=0; j<selected.length; j++){
					if (field_list.getModel().get(selected[j].getIndex()).equals("Code"))
						listModel[i][j] = resultSet.get(i).getUnitCode();
					else if (field_list.getModel().get(selected[j].getIndex()).equals("Name"))
						listModel[i][j] = resultSet.get(i).getUnitName();
					else if (field_list.getModel().get(selected[j].getIndex()).equals("College"))
						listModel[i][j] = resultSet.get(i).getCollege().getCollegeCode();
				}
			}
		}
		
		else if (this.object.equals("Course")){
			for (int i=0; i<temp.length; i++){
				for (int j=0; j<selected.length; j++){
					if (field_list.getModel().get(selected[j].getIndex()).equals("Code"))
						listModel[i][j] = resultSet.get(i).getCourseCode();
					else if (field_list.getModel().get(selected[j].getIndex()).equals("Name"))
						listModel[i][j] = resultSet.get(i).getCourseName();
					else if (field_list.getModel().get(selected[j].getIndex()).equals("Description"))
						listModel[i][j] = resultSet.get(i).getCourseDescription();
					else if (field_list.getModel().get(selected[j].getIndex()).equals("Credit"))
						listModel[i][j] = resultSet.get(i).getUnits().toString();
					else if (field_list.getModel().get(selected[j].getIndex()).equals("Offered"))
						listModel[i][j] = Constants.MAP_ANSWER_VALUE.get(resultSet.get(i).getOffered());
					else if (field_list.getModel().get(selected[j].getIndex()).equals("Sem Offered"))
						listModel[i][j] = resultSet.get(i).getSemesterOffered();
					else if (field_list.getModel().get(selected[j].getIndex()).equals("Prereq"))
						listModel[i][j] = grammar.Converter.prefixToInfix(resultSet.get(i).getPrerequisite());
					else if (field_list.getModel().get(selected[j].getIndex()).equals("Lect Hrs"))
						listModel[i][j] = resultSet.get(i).getLectureHoursPerWeek().toString();
					else if (field_list.getModel().get(selected[j].getIndex()).equals("Min Lect Stud"))
						listModel[i][j] = resultSet.get(i).getMinimumNumberOfLectureStudents().toString();
					else if (field_list.getModel().get(selected[j].getIndex()).equals("Max Lect Stud"))
						listModel[i][j] = resultSet.get(i).getMaximumNumberOfLectureStudents().toString();
					else if (field_list.getModel().get(selected[j].getIndex()).equals("Has Lab?"))
						listModel[i][j] = Constants.MAP_ANSWER_VALUE.get(resultSet.get(i).getHasLaboratory());
					else if (field_list.getModel().get(selected[j].getIndex()).equals("Lab Hrs"))
						listModel[i][j] = resultSet.get(i).getLaboratoryHoursPerWeek().toString();
					else if (field_list.getModel().get(selected[j].getIndex()).equals("Min Lab Stud"))
						listModel[i][j] = resultSet.get(i).getMinimumNumberOfLaboratoryStudents().toString();
					else if (field_list.getModel().get(selected[j].getIndex()).equals("Max Lab Stud"))
						listModel[i][j] = resultSet.get(i).getMaximumNumberOfLaboratoryStudents().toString();
					else if (field_list.getModel().get(selected[j].getIndex()).equals("Unit"))
						listModel[i][j] = resultSet.get(i).getUnit().getUnitCode();
				}
			}
		}
		
		else if (this.object.equals("Degree Course")){
			for (int i=0; i<temp.length; i++){
				for (int j=0; j<selected.length; j++){
					if (field_list.getModel().get(selected[j].getIndex()).equals("Code"))
						listModel[i][j] = resultSet.get(i).getDegreeCode();
					else if (field_list.getModel().get(selected[j].getIndex()).equals("Name"))
						listModel[i][j] = resultSet.get(i).getDegreeName();
					else if (field_list.getModel().get(selected[j].getIndex()).equals("College"))
						listModel[i][j] = resultSet.get(i).getCollege().getCollegeCode();
				}
			}
		}
		
		
		else if (this.object.equals("Curriculum")){
			for (int i=0; i<temp.length; i++){
				for (int j=0; j<selected.length; j++){
					if (field_list.getModel().get(selected[j].getIndex()).equals("Curriculum Code"))
						listModel[i][j] = resultSet.get(i).getCurriculumCode();
					else if (field_list.getModel().get(selected[j].getIndex()).equals("Curriculum Name"))
						listModel[i][j] = resultSet.get(i).getCurriculumName();
					else if (field_list.getModel().get(selected[j].getIndex()).equals("Total Units"))
						listModel[i][j] = resultSet.get(i).getTotalUnits().toString();
					else if (field_list.getModel().get(selected[j].getIndex()).equals("AH Count"))
						listModel[i][j] = resultSet.get(i).getAHCount().toString();
					else if (field_list.getModel().get(selected[j].getIndex()).equals("MST Count"))
						listModel[i][j] = resultSet.get(i).getMSTCount().toString();
					else if (field_list.getModel().get(selected[j].getIndex()).equals("SSP Count"))
						listModel[i][j] = resultSet.get(i).getSSPCount().toString();
					else if (field_list.getModel().get(selected[j].getIndex()).equals("Elective Count"))
						listModel[i][j] = resultSet.get(i).getElectiveCount().toString();
					else if (field_list.getModel().get(selected[j].getIndex()).equals("Degree Code"))
						listModel[i][j] = resultSet.get(i).getDegreeCourse().getDegreeCode();
				}
			}
		}
		
		ListModel strset = new ListModelList(listModel);
		result_list.setModel(strset);
		result_list.setItemRenderer(new DataItemRenderer());
		
	}
}